**---------------------------------------------------------------------------------
** Paper: Redistributive Preferences?
** Authors: Lars Pelke
** Contact: lars.pelke@ipw.uni-heidelberg.de
** Journal: tba
** Replication: All tables and graphs in MANUSCRIPT

cd "insert your directory here"

***-----------------------------------------------------------*****
* Data management + 

use data/robustness_data_without_imputation.dta, clear
 estimates clear
 
gen dataset = 1 
replace dataset = 2 if data =="EVS"
replace dataset = 3 if data =="ESS"
replace dataset = 4 if data =="ISSP"
replace dataset = 5 if data =="Latinobarometer"

table(cohortmatch5_15)

table cohortmatch5_15 country_name


*center variables*

sum v2x_polyarchy, meanonly
gen v2x_polyarchy_c=v2x_polyarchy-r(mean)

sum e_migdppcln, meanonly
gen e_migdppcln_c=e_migdppcln-r(mean)


sum v2x_clphy_5, meanonly
gen v2x_clphy_5_c=v2x_clphy_5-r(mean)


sum v2exl_legitideol_5, meanonly
gen v2exl_legitideol_5_c=v2exl_legitideol_5-r(mean)

drop v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5
rename (v2x_polyarchy_c e_migdppcln_c v2x_clphy_5_c v2exl_legitideol_5_c) (v2x_polyarchy e_migdppcln v2x_clphy_5 v2exl_legitideol_5)

summarize v2x_clphy_5

* Model 1 - repression

	set more off
	xtmixed  red_pref age c.time_under_autocracy_15##c.v2x_clphy_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m1
	
	outreg2 using Output/without_imp/Table1.doc, replace ctitle(Model 1)
	
* FIGURE H10
 	
estimates restore m1
	margins ,  at(time_under_autocracy_15=(0 10 20 30 40 50 60) v2x_clphy_5=(-.5578499 0 .39615)) atmeans 
	marginsplot,	xlabel(0 (10) 60,  angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of Exposure to autocracy" "on redistribution preferences", size(medsmall)) ///
	xtitle("Exposure to autocracy (at c)", size(medsmall))  ///
	legend(order(4 "Min"  5 "Mean" 6 "Max" ) position(12) ring(0) )  ///
	title("Exposure to autocracy by Physical Integrity (at c) on preferences for redistribution.", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(figh10, replace)
	
	graph save Output/without_imp/FigureH10, replace
	graph export Output/without_imp/FigureH10.pdf, replace

	
* Model 2 - ideology

	set more off
	xtmixed  red_pref age c.time_under_autocracy_15##c.v2exl_legitideol_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m2

	outreg2 using Output/without_imp/Table2.doc, replace ctitle(Model 2)


* FIGURE H11

summarize v2exl_legitideol_5

estimates restore m2
	margins ,  at(time_under_autocracy_15=(0 10 20 30 40 50 60) v2exl_legitideol_5=(-2.817756 0 3.416244)) atmeans 	
	marginsplot,	xlabel(0 (10) 60,  angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of Exposure to autocracy" "on redistribution preferences", size(medsmall)) ///
	xtitle("Exposure to autocracy", size(medsmall))  ///
	legend(order(4 "Min"  5 "Mean" 6 "Max" ) position(12) ring(0) )  ///
	title("Exposure to autocracy by Indoctrination (at c) on preferences for redistribution.", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4e, replace)
	
	graph save Output/without_imp/FigureH11, replace
	graph export Output/without_imp/FigureH11.pdf, replace


	
* Model 3 - ideology + repression interaction

	set more off
	xtmixed  red_pref age c.time_under_autocracy_15##c.v2x_clphy_5##c.v2exl_legitideol_5 ///
	v2x_polyarchy e_migdppcln ///
	i.sex i.education_3 i.unemployed i.country_id i.dataset || country_name: R.cohortmatch5_15 || year: , var ml
	estimates store m3

outreg2 using Output/without_imp/Table3.doc, append ctitle(Model 6)

summarize v2exl_legitideol_5 v2x_clphy_5

 estimates restore m3
	margins, at(time_under_autocracy_15 = (0 10 20 30 40 50 60) v2exl_legitideol_5=(-1.712054 0  1.712054 ) v2x_clphy_5=(-.5578499 0 .39615)) atmeans
	marginsplot, by(v2exl_legitideol_5) ///
	xlabel(0 (10)60, angle(horizontal)labsize(small))   ///
	ylabel(40(1)50 ,  angle(horizontal)labsize(small))   ///
	ytitle("Marginal effect of indoctrination (at c)" "on redistribution preferences", size(medsmall)) ///
	xtitle("Exposure to autocracy", size(medsmall))  ///
	legend(order( 4 "Min"  5 "Mean" 6 "Max" ) position(6) ring(0) )  ///
	title("", size(medium)) ///
	scheme(plotplain) graphregion(fcolor(white)) name(fig4f, replace)
	
	graph save Output/without_imp/FigureH12, replace
	graph export Output/without_imp/FigureH12.pdf, replace

